/**
 * Program   :   OptionListServiceImpl.java
 * Author    :   shadow guo
 * Create    :   2013-6-25 上午11:36:34
 *
 * Copyright 2008 by Tongfu Information Technology Co. Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Tongfu Information Technology Co. Ltd. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Tongfu Information Technology Co. Ltd.
 * 
 */
package com.tongfusoft.example.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.tongfusoft.web.core.Constant;
import com.tongfusoft.web.core.data.DictionaryData;
import com.tongfusoft.web.core.data.OptionData;
import com.tongfusoft.web.core.service.IOptionListService;
import com.tongfusoft.web.utils.ParameterUtils;

public class OptionListServiceImpl implements IOptionListService{

	@Override
	public Map<String, List<OptionData>> getOptions(Map params) {
		//获取查询的key，固定值：dictCode
		String dictCodes = (String)params.get(Constant.REQDICTCODE);
		
		String[] dictCode = StringUtils.split(dictCodes, ",");
		
		String currProject = (String)params.get(Constant.CURRPROJECT);
		
		Map<String,List<OptionData>> result = new HashMap<String,List<OptionData>>();
		
		for(int i=0;dictCode != null && i<dictCode.length;i++){
			List<DictionaryData> dicts =  ParameterUtils.findDictionaryByCode((Map<String,Map<String,List<DictionaryData>>>)params.get(Constant.DICTIONARY), dictCode[i],currProject);
			
			if(dicts == null){
				dicts = Collections.EMPTY_LIST;
			}
			
			result.put(dictCode[i], getOptions(dicts));
			
		}
		
		
		return result;
	}
	
	
	private List<OptionData> getOptions(List<DictionaryData> dicts){
		List<OptionData> list = new ArrayList<OptionData>();
		
		for(DictionaryData dict : dicts){
			list.add(dict.getOptionData());
		}
		
		return list;
		
	}

}
